package EveryDay;
/*
* 直接遍历 时间复杂度O（n）
* */
public class P2073 {
    public static void main(String[] args) {
        int[] a={2,3,2};
        int k=2;
        Solution solution=new Solution();
        System.out.println(solution.timeRequiredToBuy(a,k));
    }
}

class Solution {
    public int timeRequiredToBuy(int[] tickets, int k) {
        int length=tickets.length;
        int time=0;
        int i=0;
//        int num=tickets[k-1];
        while(tickets[k]>0){
            if(tickets[i]>0){
                tickets[i]--;
                time++;
            }
            i=(i+1)%length;

        }
        return time;
    }
}
